var status;
var itemz = Array(1012108, 1012109, 1012110, 1012111);
var chosen;
var str;
var dex;
var intt;
var luk;
var boxes;
var lol;

function start() {
	status = -1;
	chosen = 0;
	str = 0;
	dex = 0;
	intt = 0;
	luk = 0;
	boxes = 0;
	lol = 1;
	action(1, 0, 0);
}

function action(mode, type, selection) {
	if (mode == -1) {
		cm.dispose();
	} else {
		if (mode == 0) {
			cm.sendOk("GoodBye");
			cm.dispose();
			return;
		}
		if (mode == 1)
			status++;
		else
			status--;
		if (status == 0) {
			cm.sendYesNo("Hello, I am the item creator\r\nIn order to use me you must have 5 golden boxes\r\nDo you want to create an item?");
		} else if (status == 1) {
			if (cm.itemQuantity(4280000) >= 5) {
				var text = "What item do you wish to create?\r\n";
				for (var i = 0; i < itemz.length; i++) {
					text += ("#L" + i + "##v" + itemz[i] + "##l\r\n");
				}
				cm.sendSimple(text);
				boxes = (cm.itemQuantity(4280000) - 5);
			} else {
				cm.sendOk("You don't have enough boxes");
				cm.dispose();
			}
    		} else if (status == 2) {
			chosen = itemz[selection];
			cm.sendNext("Ah, you have chosen a #v" + chosen + "#\r\nYou have #r" + boxes + "#k boxes left\r\n\r\nThe current item stats are:\r\n#b0 Str\r\n0 Dex\r\n0 Int\r\n0 Luk#k");
		} else if (status == 3) {
			if (boxes > 0 && lol == 1) {
				cm.sendSimple("You have #r" + boxes + "#k boxes left\r\nThe current item stats are:\r\n#b" + str + "#k Str,\r\n#b" + dex + "#k Dex,\r\n#b" + intt + "#k Int,\r\n#b" + luk + "#k Luk\r\n\r\nI want to use 1 Golden box to add#b\r\n\r\n#L1#2 Str#l\r\n#L2#2 Dex#l\r\n#L3#2 Int#l\r\n#L4#2 Luk#l\r\n#L5#Nothing, i'm done creating my item#l#k");
			} else {
				cm.sendYesNo("Do you really want to pay me #r" + (cm.itemQuantity(4280000) - boxes) + "#k boxes?\r\n#v" + chosen + "# would have:\r\n#b" + str + "#k Str,\r\n#b" + dex + "#k Dex,\r\n#b" + intt + "#k Int,\r\n#b" + luk + "#k Luk");
				status++;
			}
		} else if (status == 4) {
			switch (selection) {
				case 1:
					str += 2;
					break;
				case 2:
					dex += 2;
					break;
				case 3:
					intt += 2;
					break;
				case 4:
					luk += 2;
					break;
				default:
					lol = 0;
					status--;
					boxes++;
					break;
			}
			boxes--;
			if (lol == 1 && boxes > 0)
				cm.sendSimple("You have #r" + boxes + "#k boxes left\r\nThe current item stats are:\r\n#b" + str + "#k Str,\r\n#b" + dex + "#k Dex,\r\n#b" + intt + "#k Int,\r\n#b" + luk + "#k Luk\r\n\r\nI want to use 1 Golden box to add#b\r\n\r\n#L1#2 Str#l\r\n#L2#2 Dex#l\r\n#L3#2 Int#l\r\n#L4#2 Luk#l\r\n#L5#Nothing, i'm done creating my item#l#k");
			else {
				cm.sendYesNo("Do you really want to pay me #r" + (cm.itemQuantity(4280000) - boxes) + "#k boxes?\r\n#v" + chosen + "# would have:\r\n#b" + str + "#k Str,\r\n#b" + dex + "#k Dex,\r\n#b" + intt + "#k Int,\r\n#b" + luk + "#k Luk");
				status++;
				status++;
			}
			status--;
			status--;
			status++;
		} else {
			if (cm.canHold(1000000)) {
				cm.createEquip(chosen, str, dex, intt, luk);
				cm.sendOk("Here you go");
				cm.gainItem(4280000, -(cm.itemQuantity(4280000) - boxes));
				cm.dispose();
			} else {
				cm.sendOk("You don't have enough room in your inventory");
				cm.dispose();
			}
		}
	} 
}